package com.cuitrip.util;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.ArrayAdapter;

import com.cuitrip.apiservice.BusinessHelper;
import com.cuitrip.app.MainApplication;
import com.cuitrip.service.BuildConfig;
import com.cuitrip.util.track.TrackUtil;
import com.lab.utils.MessageUtils;
import com.lab.utils.ToastUtil;

/**
 * Created by MiJack on 2015/11/26.
 */
public class DebugUtil {
    public static void showTestDialog(final Context context) {
        if (!BuildConfig.DEBUG){
            return;
        }
        AlertDialog.Builder builder = MessageUtils.createHoloBuilder(context);
        builder.setTitle("调试信息");
        ArrayAdapter<String> textAdapter = new ArrayAdapter<String>(context,android.R.layout.simple_expandable_list_item_1);
        textAdapter.add("渠道：" + MainApplication.getInstance().getChannelName());
        textAdapter.add("api host:" + BusinessHelper.API_URL);
        textAdapter.add("埋点toast 开关:" + TrackUtil.isShowToast);
        builder.setAdapter(textAdapter, new Dialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int position) {
                if (position == 1) {
                    showHostDialog(context);
                }else if (position == 2){
                    showTrackDialog(context);
                }
            }
        });
        builder.show();
    }

    private static void showTrackDialog(Context context){
        AlertDialog.Builder builder = MessageUtils.createHoloBuilder(context);
        builder.setTitle("当前埋点开关：" + TrackUtil.isShowToast);
        ArrayAdapter<String> textAdapter = new ArrayAdapter<String>(context,android.R.layout.simple_expandable_list_item_1);
        textAdapter.add("关闭");
        textAdapter.add("打开");
        builder.setAdapter(textAdapter, new Dialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int position) {
                if (position == 0) {
                    TrackUtil.setShowToast(false);
                } else if (position == 1) {
                    TrackUtil.setShowToast(true);
                }
            }
        });
        builder.show();
    }

    private static void showHostDialog(Context context){
        AlertDialog.Builder builder = MessageUtils.createHoloBuilder(context);
        builder.setTitle("当前api host：" + BusinessHelper.API_URL);
        ArrayAdapter<String> textAdapter = new ArrayAdapter<String>(context,android.R.layout.simple_expandable_list_item_1);
        textAdapter.add("dev 环境：" + BusinessHelper.BASE_DEV_URL);
        textAdapter.add("pre 环境：" + BusinessHelper.BASE_PRE_URL);
        textAdapter.add("online 环境：" + BusinessHelper.BASE_ONLINE_URL);
        builder.setAdapter(textAdapter, new Dialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int position) {
                if (position == 0) {
                    BusinessHelper.setApiHost(BusinessHelper.BASE_DEV_URL);
                } else if (position == 1) {
                    BusinessHelper.setApiHost(BusinessHelper.BASE_PRE_URL);
                } else if (position == 2) {
                    BusinessHelper.setApiHost(BusinessHelper.BASE_ONLINE_URL);
                }
            }
        });
        builder.show();
    }

}
